package cn.iocoder.yudao.module.system.controller.admin.config;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.config.vo.SystemConfigSaveReqVO;
import cn.iocoder.yudao.module.system.controller.app.config.vo.AppSystemInfoRespVO;
import cn.iocoder.yudao.module.system.service.config.SystemConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - Look-IM系统配置")
@RestController
@RequestMapping("/system/look-im-config")
@Validated
public class SystemConfigController {

    @Resource
    private SystemConfigService systemConfigService;

    @GetMapping("/get")
    @Operation(summary = "获取Look-IM系统配置")
    @PreAuthorize("@ss.hasPermission('system:config:query')")
    public CommonResult<AppSystemInfoRespVO> getSystemConfig() {
        AppSystemInfoRespVO config = systemConfigService.getSystemConfig();
        return success(config);
    }

    @PutMapping("/update")
    @Operation(summary = "更新Look-IM系统配置")
    @PreAuthorize("@ss.hasPermission('system:config:update')")
    public CommonResult<Boolean> updateSystemConfig(@Valid @RequestBody SystemConfigSaveReqVO updateReqVO) {
        systemConfigService.updateSystemConfig(updateReqVO);
        return success(true);
    }

    @PostMapping("/reset")
    @Operation(summary = "重置Look-IM系统配置为默认值")
    @PreAuthorize("@ss.hasPermission('system:config:update')")
    public CommonResult<Boolean> resetSystemConfig() {
        systemConfigService.resetSystemConfig();
        return success(true);
    }
}